package com.game.worm.mobile.view.search;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import com.dx.as.ToolBarOptions;
import com.dx.as.UI;
import com.game.worm.mobile.R;
import com.game.worm.mobile.bean.GameBean;
import com.game.worm.mobile.view.search.adpater.SearchAdpater;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by d_xxiang on 2018/3/28.
 */

public class SearchActivity extends UI{
    private SearchAdpater searchAdpater;
    @Override
    protected void onActivityCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_search);
        initToolBarView();
        initView();
    }

    private void initToolBarView(){
        ToolBarOptions toolBarOptions = new ToolBarOptions();
        toolBarOptions.toolView = View.inflate(this, R.layout.activity_search_top,null);
        toolBarOptions.toolView.findViewById(R.id.back).setOnClickListener(onClickListener);
        toolBarOptions.toolView.findViewById(R.id.search).setOnClickListener(onClickListener);
        setToolbar(toolBarOptions);
    }

    private void initView(){
        RecyclerView hotSearch = findViewById(R.id.recyclerview_hotsearh);
        hotSearch.setLayoutManager(new GridLayoutManager(this, 2));
        searchAdpater = new SearchAdpater(this);
        hotSearch.setAdapter(searchAdpater);

        getTestData();

        RecyclerView record = findViewById(R.id.recyclerview_record);
        record.setLayoutManager(new GridLayoutManager(this, 4));
        SearchAdpater recordAdpater = new SearchAdpater(this);
        recordAdpater.setData(getTestDataRecord());
        record.setAdapter(recordAdpater);
    }

    private List<GameBean> getTestDataRecord(){
        List<GameBean> list = new ArrayList<>();
        for (int i = 0; i < 6; i ++){
            list.add(new GameBean());
        }
        return list;
    }


    private void getTestData(){
        List<GameBean> list = new ArrayList<>();
        for (int i = 0; i < 10; i ++){
            list.add(new GameBean());
        }
        searchAdpater.setData(list);
    }

    public void onViewClick(View view){
        switch (view.getId()){
            case R.id.class_demo: //有奖试玩
                break;
            case R.id.class_crack://汉化破解
                break;
            case R.id.game_topic://游戏话题圈
                break;
            case R.id.clear://清空搜索历史
                break;
        }
    }


    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.back://返回上一页
                    finish();
                    break;
                case R.id.search://网络请求搜索
                    break;
            }
        }
    };


}
